package com.lgc.demo;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class ElementOperate {
    private static ChromeDriver driver;

    public static void main(String[] args) throws InterruptedException {
        ChromeDriver driver = oponChrome();
//        driver.findElement(By.id("kw")).sendKeys("12331223");
//        Thread.sleep(3000);
//        driver.findElement(By.id("kw")).clear();

//        WebElement webElement = driver.findElement(By.id("kw"));
//        System.out.println(webElement.getTagName());
//        System.out.println(webElement.getAttribute("maxlength"));

//        WebElement hao = driver.findElement(By.partialLinkText("o123"));
//        System.out.println(hao.getText());

        driver.findElement(By.id("kw")).sendKeys("腾讯课堂");
        driver.findElement(By.id("su")).click();
        System.out.println(driver.getWindowHandle());
        System.out.println("所有句柄："+ driver.getWindowHandles());
        Thread.sleep(2000);
        driver.findElement(By.className("normal-radius_h9O_G")).click();
        System.out.println(driver.getWindowHandle());
        Thread.sleep(3000);


        // 创建WebDriverWait对象，设置等待时间为10秒
        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

        // 等待元素可见
        WebElement element = wait.until(ExpectedConditions
                .visibilityOfElementLocated(By.xpath("//a[text()='(ke.qq.com)']")));
        driver.findElement(By.xpath("//a[text()='(ke.qq.com)']"));

    }
    private static ChromeDriver oponChrome() {
        // 设置驱动程序的路径
        System.setProperty("webdriver.chrome.driver", "E:\\桌面 1\\selenium4QQDemo\\src\\main\\resources\\chromedriver.exe");
        // 创建Edge浏览器驱动
        ChromeDriver driver = new ChromeDriver();
        driver.get("https://www.baidu.com");

        return driver;
    }

}
